package com.forekenow.Demo11.exerce;

import java.util.*;

public class Practice1 {
    public static void main(String[] args) {
        String[] strArr = {"aaa","ccc","vvv","nnn","aaa","ccc","vvv","ddd","eee","eee","ddd","ccc","aaa","vvv","nnn"};
        List<String> list = new ArrayList<>();
        Set<String> set = new HashSet<>();
        for (String str : strArr) {
            list.add(str);
            set.add(str);
        }
        for (String str : set) {
            int num = Collections.frequency(list, str);
            System.out.printf("%s出现的次数为%d\n",str,num);
        }


//        Map<String,Integer> map = new HashMap<>();
//        for (int i = 0; i < strArr.length; i++) {
//            if (map.containsKey(strArr[i])){
//                map.put(strArr[i],map.get(strArr[i])+1);
//            }else {
//                map.put(strArr[i],1);
//            }
//        }
//
//        Set<Map.Entry<String, Integer>> entries = map.entrySet();
//        Iterator<Map.Entry<String, Integer>> iterator = entries.iterator();
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }
    }
}
